<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
    <li class="active"><a href="#A" data-toggle="tab">账号配置</a></li>
</ul>
<form class="form-horizontal js-ajax-forms" action="{:U('setting/site_post')}" method="post">
    <fieldset>
        <div class="tabbable">
            <div class="tab-content">
                <div class="tab-pane active" id="A">
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label">appID:</label>
                            <div class="controls">
                                <input type="text" name="options[appid]" value="{$appid}"><span class="form-required">*</span>
                                <php>if($option_id):</php>
                                <input type="hidden" name="option_id" value="{$option_id}">
                                <php>endif;</php>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">appsecret:</label>
                            <div class="controls">
                                <input type="text" name="options[appsecret]" value="{$appsecret}"><span class="form-required">*</span>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">Token:</label>
                            <div class="controls">
                                <input type="text" name="options[token]" value="{$token}"  id="js-site-admin-url-password"><span class="form-required">*</span>
                            </div>
                        </div>


                    </fieldset>
                </div>

            </div>
        </div>

        <div class="form-actions">
            <button type="submit" class="btn btn-primary  js-ajax-submit">{:L("SAVE")}</button>
        </div>
    </fieldset>
</form>

</div>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script>
    /////---------------------

    Wind.use('validate', 'ajaxForm', 'artDialog', function () {
        //javascript
        var form = $('form.js-ajax-forms');
        //ie处理placeholder提交问题
        if ($.browser.msie) {
            form.find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        }
        //表单验证开始
        form.validate({
            //是否在获取焦点时验证
            onfocusout: false,
            //是否在敲击键盘时验证
            onkeyup: false,
            //当鼠标掉级时验证
            onclick: false,
            //验证错误
            showErrors: function (errorMap, errorArr) {
                //errorMap {'name':'错误信息'}
                //errorArr [{'message':'错误信息',element:({})}]
                try {
                    $(errorArr[0].element).focus();
                    art.dialog({
                        id: 'error',
                        icon: 'error',
                        lock: true,
                        fixed: true,
                        background: "#CCCCCC",
                        opacity: 0,
                        content: errorArr[0].message,
                        cancelVal: "{:L('OK')}",
                        cancel: function () {
                            $(errorArr[0].element).focus();
                        }
                    });
                } catch (err) {
                }
            },
            //验证规则
            rules: {
                'options[appid]': {
                    required: 1
                },
                'options[appsecret]': {
                    required: 1
                },
                'options[token]': {
                    required: 1
                }
            },
            //验证未通过提示消息
            messages: {
                'options[appID]': {
                    required: "appID 不能为空!"
                },
                'options[appsecret]': {
                    required: "appsecret不能为空"
                },
                'options[token]': {
                    required: "token不能为空"
                }
            },
            //给未通过验证的元素加效果,闪烁等
            highlight: false,
            //是否在获取焦点时验证
            onfocusout: false,
            //验证通过，提交表单
            submitHandler: function (forms) {
                $(forms).ajaxSubmit({
                    url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                    dataType: 'json',
                    beforeSubmit: function (arr, $form, options) {

                    },
                    success: function (data, statusText, xhr, $form) {
                        if (data.status) {
//                            setCookie("refersh_time", 1);
//                            var admin_url_changed = $("#js-site-admin-url-password").data("changed");
//                            var message = admin_url_changed ? data.info + '<br><span style="color:red;">后台地址已更新(请劳记！)</span>' : data.info;

                            //添加成功
                            Wind.use("artDialog", function () {
                                art.dialog({
                                    id: "succeed",
                                    icon: "succeed",
                                    fixed: true,
                                    lock: true,
                                    background: "#CCCCCC",
                                    opacity: 0,
                                    content: message,
                                    button: [{
                                        name: "{:L('OK')}",
                                        callback: function () {
                                            reloadPage(window);
                                            return true;
                                        },
                                        focus: true
                                    }, {
                                        name: "{:L('CLOSE')}",
                                        callback: function () {
                                            reloadPage(window);
                                            return true;
                                        }
                                    }]
                                });
                            });
                        } else {
                            alert(data.info);
                        }
                    }
                });
            }
        });
    });
    ////-------------------------
</script>
</body>
</html>